home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 3.7 KB | 186 lines | [TEXT/MPS ] |
- PROGRAM GrayishOutlines;
-
- USES Dialogs, Fonts, Menus, OSEvents, SegLoad, Traps;
-
- VAR
- gWP: WindowPtr;
- gDone: Boolean;
-
- {------------------------------------------------}
-
- FUNCTION TrapAvailable(theTrap: Integer): Boolean;
- CONST
- _Initgraf = $A86E;
- _Unimplemented = $A89F;
- VAR
- tType: Traptype;
- numToolBoxTraps: Integer;
- BEGIN
- IF Band(theTrap, $0800) > 0 THEN
- BEGIN
- tType := toolTrap;
- theTrap := Band(theTrap, $07FF);
- IF NGetTrapAddress(_Initgraf, toolTrap) = NGetTrapAddress($AA6E, toolTrap) THEN
- numToolBoxTraps := $200
- ELSE
- numToolBoxTraps := $400;
- IF theTrap > numToolBoxTraps THEN theTrap := _Unimplemented;
- END
- ELSE
- tType := OSTrap;
- TrapAvailable := (NGetTrapAddress(theTrap, tType) <>
- NGetTrapAddress(_Unimplemented, toolTrap));
- END;
-
- {------------------------------------------------}
-
- PROCEDURE InitMac;
- BEGIN
- InitGraf(@thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TeInit;
- InitDialogs(NIL);
- InitCursor;
- END;
-
- PROCEDURE InitApp;
- CONST
- _DeviceLoop = $ABCA;
- _OpenCPort = $AA00;
- Title = 'Press Key to Quit';
- VAR
- bounds: Rect;
- BEGIN
- IF NOT (TrapAvailable(_Deviceloop) AND TrapAvailable(_Opencport)) THEN
- BEGIN
- SysBeep(20);
- SysBeep(20);
- ExitToShell;
- END;
- gDone := False;
- SetRect(bounds, 10, 50, 310, 250);
- gWP := NewCWindow(NIL, bounds, title, TRUE, documentProc, WindowPtr(-1), TRUE, 0);
- Setport(gWP);
- END;
-
- PROCEDURE DoMouseDown(where: Point);
- VAR
- clickArea: Integer;
- screenRect: Rect;
- evtWind: Windowptr;
- BEGIN
- clickArea := FindWindow(where, evtWind);
- IF clickArea = inDrag THEN
- BEGIN
- screenRect := GetGrayRgn^^.rgnBBox;
- DragWindow(evtWind, Where, screenRect);
- SetPort(evtWind);
- InvalRect(evtWind^.Portrect);
- END
- ELSE IF clickArea = inGoAway THEN
- IF TrackGoAway(evtWind, where) THEN gDone := TRUE
- END;
-
- PROCEDURE Button1;
- VAR
- color: RGBColor;
- pp: PixPatHandle;
- r: Rect;
- BEGIN
- color.Red := $8000;
- color.Green := $8000;
- color.Blue := $8000;
- pp := NewPixPat;
- MakeRGBPat(pp, color);
- PenPixPat(pp);
- PenSize(4, 4);
- SetRect(r, 50, 50, 250, 70);
- FrameRoundRect(r, 10, 10);
- PenNormal;
- MoveTo(60, 65);
- DrawString('PixPat version');
- DisposPixPat(pp);
- END;
-
- PROCEDURE Mydrawingproc(depth: Integer;
- deviceFlags: Integer;
- targetDevice: GDHandle;
- userData: Longint);
- VAR
- color: RGBColor;
- r: Rect;
- BEGIN
- IF depth > 1 THEN
- BEGIN
- color.Red := $8000;
- color.Green := $8000;
- color.Blue := $8000;
- Rgbforecolor(color);
- END
- ELSE
- BEGIN
- Penpat(Gray);
- END;
- PenSize(4, 4);
- SetRect(r, 50, 120, 250, 140);
- FrameRoundRect(r, 10, 10);
- PenNormal;
- color.Red := $0000;
- color.Green := $0000;
- color.Blue := $0000;
- RGBForeColor(color);
- MoveTo(60, 135);
- DrawString('Drawn through DeviceLoop');
- END;
-
- PROCEDURE Button2;
- VAR
- userData: Longint;
- flags: DeviceLoopFlags; {see Vol. VI, 21-24 }
- BEGIN
- userData := 0; {not used here}
- flags := [];
- DeviceLoop(gWP^.visRgn, @myDrawingProc, userData, flags);
- END;
-
- PROCEDURE DoUpdate(evtWind: Windowptr);
- VAR
- savePort: Grafptr;
- BEGIN
- IF evtWind = gWP THEN
- BEGIN
- GetPort(savePort);
- SetPort(gWP);
- BeginUpdate(gWP);
- {• EraseRect(gWP^.portRect); •}
- Button1;
- Button2;
- EndUpdate(gWP);
- SetPort(savePort);
- END;
- END;
-
- PROCEDURE Maineventloop;
- VAR
- anEvent: EventRecord;
- evtWind: WindowPtr;
- BEGIN
- REPEAT
- IF WaitNextEvent(everyEvent, anEvent, 60, NIL) THEN
- CASE anEvent.what OF
- keyDown: gDone := True;
- MouseDown: DoMouseDown(anEvent.Where);
- updateEvt: DoUpdate(WindowPtr(anEvent.Message));
- END
- UNTIL gDone;
- END;
-
- BEGIN
- InitMac;
- InitApp;
- MainEventLoop;
- END.
-